<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT">










<meta name="description" content="如果有天我们湮没在人潮中,庸碌一生,那是因为我们没有努力要活的丰盛">
<meta property="og:type" content="website">
<meta property="og:title" content="无名小卒">
<meta property="og:url" content="http://chinawfsl.gitee.io/blog/index.html">
<meta property="og:site_name" content="无名小卒">
<meta property="og:description" content="如果有天我们湮没在人潮中,庸碌一生,那是因为我们没有努力要活的丰盛">
<meta property="og:locale" content="zh-Hans">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="无名小卒">
<meta name="twitter:description" content="如果有天我们湮没在人潮中,庸碌一生,那是因为我们没有努力要活的丰盛">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://chinawfsl.gitee.io/blog/">





  <title>无名小卒</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left 
  page-home">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">无名小卒</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">天下风云出我辈,一入江湖岁月催,皇图霸业谈笑中,不胜人生一场醉</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">
    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://chinawfsl.gitee.io/blog/blog/2019/03/21/Java-code-generator/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="无名小卒">
      <meta itemprop="description" content>
      <meta itemprop="image" content="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1553150146014&di=dc4e5d4bdfbc647f7eca1367401dbc47&imgtype=0&src=http%3A%2F%2Fs9.knowsky.com%2Fbizhi%2Fl%2F20090606%2F200906186%2520%25281%2529.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="无名小卒">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2019/03/21/Java-code-generator/" itemprop="url">Java代码生成器</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-03-21T16:27:24+08:00">
                2019-03-21
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/Java/" itemprop="url" rel="index">
                    <span itemprop="name">Java</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h2 id="在我们日常的开发中常常因为要新建一个个controller，service等影响我们的开发效率，所以在此弄了一个代码自动生成器，这个自动生成器使用了mybatis-generator和mybatis-plus两种技术-在这记录一下也是防止以后忘记，废话不多说，直接上代码"><a href="#在我们日常的开发中常常因为要新建一个个controller，service等影响我们的开发效率，所以在此弄了一个代码自动生成器，这个自动生成器使用了mybatis-generator和mybatis-plus两种技术-在这记录一下也是防止以后忘记，废话不多说，直接上代码" class="headerlink" title="在我们日常的开发中常常因为要新建一个个controller，service等影响我们的开发效率，所以在此弄了一个代码自动生成器，这个自动生成器使用了mybatis-generator和mybatis-plus两种技术,在这记录一下也是防止以后忘记，废话不多说，直接上代码"></a>在我们日常的开发中常常因为要新建一个个controller，service等影响我们的开发效率，所以在此弄了一个代码自动生成器，这个自动生成器使用了mybatis-generator和<a href="https://mp.baomidou.com/" target="_blank" rel="noopener">mybatis-plus</a>两种技术,在这记录一下也是防止以后忘记，废话不多说，直接上代码</h2><h3 id="以下是要用到的包（把整个pom文件都给你们，里面还有其他插件，自己选择性使用）"><a href="#以下是要用到的包（把整个pom文件都给你们，里面还有其他插件，自己选择性使用）" class="headerlink" title="以下是要用到的包（把整个pom文件都给你们，里面还有其他插件，自己选择性使用）"></a>以下是要用到的包（把整个pom文件都给你们，里面还有其他插件，自己选择性使用）</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">project</span> <span class="attr">xmlns</span>=<span class="string">"http://maven.apache.org/POM/4.0.0"</span> <span class="attr">xmlns:xsi</span>=<span class="string">"http://www.w3.org/2001/XMLSchema-instance"</span></span></span><br><span class="line"><span class="tag">  <span class="attr">xsi:schemaLocation</span>=<span class="string">"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">modelVersion</span>&gt;</span>4.0.0<span class="tag">&lt;/<span class="name">modelVersion</span>&gt;</span></span><br><span class="line"></span><br><span class="line">  <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.william<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>mybatis-generator<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">version</span>&gt;</span>1.0-SNAPSHOT<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">packaging</span>&gt;</span>jar<span class="tag">&lt;/<span class="name">packaging</span>&gt;</span></span><br><span class="line"></span><br><span class="line">  <span class="tag">&lt;<span class="name">name</span>&gt;</span>mybatis-generator<span class="tag">&lt;/<span class="name">name</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">url</span>&gt;</span>http://maven.apache.org<span class="tag">&lt;/<span class="name">url</span>&gt;</span></span><br><span class="line"></span><br><span class="line">  <span class="tag">&lt;<span class="name">properties</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">project.build.sourceEncoding</span>&gt;</span>UTF-8<span class="tag">&lt;/<span class="name">project.build.sourceEncoding</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">jdk.version</span>&gt;</span>1.8<span class="tag">&lt;/<span class="name">jdk.version</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- Mybatis | Mybatis puls | mysql | druid --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">mybatisplus-spring-boot-starter.version</span>&gt;</span>2.1.9<span class="tag">&lt;/<span class="name">mybatisplus-spring-boot-starter.version</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">mybatisplus.version</span>&gt;</span>2.2.0<span class="tag">&lt;/<span class="name">mybatisplus.version</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">velocity.version</span>&gt;</span>1.7<span class="tag">&lt;/<span class="name">velocity.version</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">mysql.version</span>&gt;</span>5.1.38<span class="tag">&lt;/<span class="name">mysql.version</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">properties</span>&gt;</span></span><br><span class="line"></span><br><span class="line">  <span class="tag">&lt;<span class="name">dependencies</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- mybatis-plus begin --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.baomidou<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>mybatis-plus-boot-starter<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">version</span>&gt;</span>$&#123;mybatisplus-spring-boot-starter.version&#125;<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">exclusions</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">exclusion</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>tomcat-jdbc<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.apache.tomcat<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">exclusion</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;/<span class="name">exclusions</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">&lt;!-- 代码生成器所需jar --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>velocity<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.apache.velocity<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">version</span>&gt;</span>$&#123;velocity.version&#125;<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>mysql<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>mysql-connector-java<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">version</span>&gt;</span>$&#123;mysql.version&#125;<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.baomidou<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>mybatis-plus<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">version</span>&gt;</span>$&#123;mybatisplus.version&#125;<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">&lt;!--swagger UI --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.didispace<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-swagger<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">version</span>&gt;</span>1.2.0.RELEASE<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- https://mvnrepository.com/artifact/com.alibaba/fastjson --&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">	    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.alibaba<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">	    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>fastjson<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">	    <span class="tag">&lt;<span class="name">version</span>&gt;</span>1.2.47<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">dependencies</span>&gt;</span></span><br><span class="line"></span><br><span class="line">  <span class="tag">&lt;<span class="name">build</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">plugins</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">plugin</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-maven-plugin<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">configuration</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">fork</span>&gt;</span>true<span class="tag">&lt;/<span class="name">fork</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">executable</span>&gt;</span>true<span class="tag">&lt;/<span class="name">executable</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">configuration</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;/<span class="name">plugin</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">plugin</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.apache.maven.plugins<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>maven-compiler-plugin<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">version</span>&gt;</span>2.3.2<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">configuration</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">source</span>&gt;</span>$&#123;jdk.version&#125;<span class="tag">&lt;/<span class="name">source</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">target</span>&gt;</span>$&#123;jdk.version&#125;<span class="tag">&lt;/<span class="name">target</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">encoding</span>&gt;</span>UTF-8<span class="tag">&lt;/<span class="name">encoding</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">configuration</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;/<span class="name">plugin</span>&gt;</span></span><br><span class="line">      <span class="comment">&lt;!--Skip Test True--&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">plugin</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.apache.maven.plugins<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>maven-surefire-plugin<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">configuration</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">skip</span>&gt;</span>true<span class="tag">&lt;/<span class="name">skip</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">configuration</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;/<span class="name">plugin</span>&gt;</span></span><br><span class="line">      <span class="comment">&lt;!--Maven的清洁插件默认情况下，将删除目标目录--&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">plugin</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.apache.maven.plugins<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>maven-clean-plugin<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">version</span>&gt;</span>2.5<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;/<span class="name">plugin</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">plugin</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.apache.maven.plugins<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>maven-install-plugin<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">version</span>&gt;</span>2.5.2<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;/<span class="name">plugin</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">plugins</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">build</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">project</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="以下是主方法，也就是执行main的方法，MpGenerator-java"><a href="#以下是主方法，也就是执行main的方法，MpGenerator-java" class="headerlink" title="以下是主方法，也就是执行main的方法，MpGenerator.java"></a>以下是主方法，也就是执行main的方法，MpGenerator.java</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.generator.AutoGenerator;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.generator.InjectionConfig;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.generator.config.*;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.generator.config.rules.DbColumnType;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.generator.config.rules.DbType;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.HashMap;</span><br><span class="line"><span class="keyword">import</span> java.util.Map;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * &lt;p&gt;</span></span><br><span class="line"><span class="comment"> * 代码生成器演示</span></span><br><span class="line"><span class="comment"> * &lt;/p&gt;</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MpGenerator</span> </span>&#123;</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * &lt;p&gt;</span></span><br><span class="line"><span class="comment">     * MySQL 生成演示</span></span><br><span class="line"><span class="comment">     * &lt;/p&gt;</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        AutoGenerator mpg = <span class="keyword">new</span> AutoGenerator();</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 全局配置</span></span><br><span class="line">        GlobalConfig gc = <span class="keyword">new</span> GlobalConfig();</span><br><span class="line">        gc.setOutputDir(<span class="string">"E:/ceshi"</span>);<span class="comment">//输出目录</span></span><br><span class="line">        gc.setFileOverride(<span class="keyword">true</span>);</span><br><span class="line">        gc.setActiveRecord(<span class="keyword">true</span>);<span class="comment">// 不需要ActiveRecord特性的请改为fals</span></span><br><span class="line">        gc.setEnableCache(<span class="keyword">false</span>);<span class="comment">// XML 二级缓存</span></span><br><span class="line">        gc.setBaseResultMap(<span class="keyword">true</span>);<span class="comment">// XML ResultMap</span></span><br><span class="line">        gc.setBaseColumnList(<span class="keyword">false</span>);<span class="comment">// XML columList</span></span><br><span class="line">        gc.setAuthor(<span class="string">"caidong"</span>);<span class="comment">//作者</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">// 自定义文件命名，注意 %s 会自动填充表实体属性！</span></span><br><span class="line">        <span class="comment">// gc.setMapperName("%sDao");</span></span><br><span class="line">        <span class="comment">// gc.setXmlName("%sDao");</span></span><br><span class="line">         gc.setServiceName(<span class="string">"%sService"</span>);</span><br><span class="line">        <span class="comment">// gc.setServiceImplName("%sServiceDiy");</span></span><br><span class="line">        <span class="comment">// gc.setControllerName("%sAction");</span></span><br><span class="line">        mpg.setGlobalConfig(gc);</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 数据源配置</span></span><br><span class="line">        DataSourceConfig dsc = <span class="keyword">new</span> DataSourceConfig();</span><br><span class="line">        dsc.setDbType(DbType.MYSQL);</span><br><span class="line">        dsc.setTypeConvert(<span class="keyword">new</span> MySqlTypeConvert() &#123;</span><br><span class="line">            <span class="comment">// 自定义数据库表字段类型转换【可选】</span></span><br><span class="line">            <span class="meta">@Override</span></span><br><span class="line">            <span class="function"><span class="keyword">public</span> DbColumnType <span class="title">processTypeConvert</span><span class="params">(String fieldType)</span> </span>&#123;</span><br><span class="line">                System.out.println(<span class="string">"转换类型："</span> + fieldType);</span><br><span class="line">                <span class="comment">// 注意！！processTypeConvert 存在默认类型转换，如果不是你要的效果请自定义返回、非如下直接返回。</span></span><br><span class="line">                <span class="keyword">return</span> <span class="keyword">super</span>.processTypeConvert(fieldType);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line">        dsc.setDriverName(<span class="string">"com.mysql.jdbc.Driver"</span>);</span><br><span class="line">        dsc.setUsername(<span class="string">"root"</span>);</span><br><span class="line">        dsc.setPassword(<span class="string">"123456"</span>);</span><br><span class="line">        dsc.setUrl(<span class="string">"jdbc:mysql://localhost:3306/family_inherit?allowMultiQueries=true&amp;useUnicode=true&amp;characterEncoding=UTF-8"</span>);</span><br><span class="line">        mpg.setDataSource(dsc);</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 策略配置</span></span><br><span class="line">        StrategyConfig strategy = <span class="keyword">new</span> StrategyConfig();</span><br><span class="line">        <span class="comment">// strategy.setCapitalMode(true);// 全局大写命名 ORACLE 注意</span></span><br><span class="line"><span class="comment">//        strategy.setTablePrefix(new String[]&#123;"tlog_", "tsys_"&#125;);// 此处可以修改为您的表前缀</span></span><br><span class="line">        strategy.setNaming(NamingStrategy.underline_to_camel);<span class="comment">// 表名生成策略</span></span><br><span class="line">        strategy.setInclude(<span class="keyword">new</span> String[]&#123;<span class="string">"cc_activity"</span>, <span class="string">"cc_activity_order"</span>&#125;); <span class="comment">// 需要生成的表 ，多个表名传数组</span></span><br><span class="line">        <span class="comment">// strategy.setExclude(new String[]&#123;"test"&#125;); // 排除生成的表</span></span><br><span class="line">        <span class="comment">// 自定义实体父类</span></span><br><span class="line">        <span class="comment">// strategy.setSuperEntityClass("com.baomidou.demo.TestEntity");</span></span><br><span class="line">        <span class="comment">// 自定义实体，公共字段</span></span><br><span class="line">        <span class="comment">// strategy.setSuperEntityColumns(new String[] &#123; "test_id", "age" &#125;);</span></span><br><span class="line">        <span class="comment">// 自定义 mapper 父类</span></span><br><span class="line">        <span class="comment">// strategy.setSuperMapperClass("com.baomidou.demo.TestMapper");</span></span><br><span class="line">        <span class="comment">// 自定义 service 父类</span></span><br><span class="line">        <span class="comment">// strategy.setSuperServiceClass("com.baomidou.demo.TestService");</span></span><br><span class="line">        <span class="comment">// 自定义 service 实现类父类</span></span><br><span class="line">        <span class="comment">// strategy.setSuperServiceImplClass("com.baomidou.demo.TestServiceImpl");</span></span><br><span class="line"><span class="comment">//         自定义 controller 父类</span></span><br><span class="line">         <span class="comment">//strategy.setSuperControllerClass("com.william.core.BaseController");</span></span><br><span class="line">        <span class="comment">// 【实体】是否生成字段常量（默认 false）</span></span><br><span class="line">        <span class="comment">// public static final String ID = "test_id";</span></span><br><span class="line">        <span class="comment">// strategy.setEntityColumnConstant(true);</span></span><br><span class="line">        <span class="comment">// 【实体】是否为构建者模型（默认 false）</span></span><br><span class="line">        <span class="comment">// public User setName(String name) &#123;this.name = name; return this;&#125;</span></span><br><span class="line">        <span class="comment">// strategy.setEntityBuilderModel(true);</span></span><br><span class="line">        mpg.setStrategy(strategy);</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 包配置</span></span><br><span class="line">        PackageConfig pc = <span class="keyword">new</span> PackageConfig();</span><br><span class="line">        pc.setParent(<span class="string">"com.family.server"</span>);</span><br><span class="line">        pc.setController(<span class="string">"controller"</span>);</span><br><span class="line">        pc.setEntity(<span class="string">"model"</span>);</span><br><span class="line">        pc.setMapper(<span class="string">"dao"</span>);</span><br><span class="line">        pc.setXml(<span class="string">"mapper"</span>);</span><br><span class="line">        mpg.setPackageInfo(pc);</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 注入自定义配置，可以在 VM 中使用 cfg.abc 【可无】</span></span><br><span class="line">        InjectionConfig cfg = <span class="keyword">new</span> InjectionConfig() &#123;</span><br><span class="line">            <span class="meta">@Override</span></span><br><span class="line">            <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">initMap</span><span class="params">()</span> </span>&#123;</span><br><span class="line">                Map&lt;String, Object&gt; map = <span class="keyword">new</span> HashMap&lt;String, Object&gt;();</span><br><span class="line">                map.put(<span class="string">"abc"</span>, <span class="keyword">this</span>.getConfig().getGlobalConfig().getAuthor() + <span class="string">"-mp"</span>);</span><br><span class="line">                <span class="keyword">this</span>.setMap(map);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;;</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 自定义 xxList.jsp 生成</span></span><br><span class="line"><span class="comment">//        List&lt;FileOutConfig&gt; focList = new ArrayList&lt;FileOutConfig&gt;();</span></span><br><span class="line"><span class="comment">//        focList.add(new FileOutConfig("/template/list.jsp.vm") &#123;</span></span><br><span class="line"><span class="comment">//            @Override</span></span><br><span class="line"><span class="comment">//            public String outputFile(TableInfo tableInfo) &#123;</span></span><br><span class="line"><span class="comment">//                // 自定义输入文件名称</span></span><br><span class="line"><span class="comment">//                return "/Users/van/test/my_" + tableInfo.getEntityName() + ".jsp";</span></span><br><span class="line"><span class="comment">//            &#125;</span></span><br><span class="line"><span class="comment">//        &#125;);</span></span><br><span class="line"><span class="comment">//        cfg.setFileOutConfigList(focList);</span></span><br><span class="line"><span class="comment">//        mpg.setCfg(cfg);</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">// 调整 xml 生成目录演示</span></span><br><span class="line"><span class="comment">//        focList.add(new FileOutConfig("/templates/mapper.xml.vm") &#123;</span></span><br><span class="line"><span class="comment">//            @Override</span></span><br><span class="line"><span class="comment">//            public String outputFile(TableInfo tableInfo) &#123;</span></span><br><span class="line"><span class="comment">//                return "/Users/van/test/develop/code/xml/" + tableInfo.getEntityName() + ".xml";</span></span><br><span class="line"><span class="comment">//            &#125;</span></span><br><span class="line"><span class="comment">//        &#125;);</span></span><br><span class="line"><span class="comment">//        cfg.setFileOutConfigList(focList);</span></span><br><span class="line">        mpg.setCfg(cfg);</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 关闭默认 xml 生成，调整生成 至 根目录</span></span><br><span class="line"><span class="comment">//        TemplateConfig tc = new TemplateConfig();</span></span><br><span class="line"><span class="comment">//        tc.setXml("/");</span></span><br><span class="line"><span class="comment">//        mpg.setTemplate(tc);</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">// 自定义模板配置，可以 copy 源码 mybatis-plus/src/main/resources/templates 下面内容修改，</span></span><br><span class="line">        <span class="comment">// 放置自己项目的 src/main/resources/templates 目录下, 默认名称一下可以不配置，也可以自定义模板名称</span></span><br><span class="line">        TemplateConfig tc = <span class="keyword">new</span> TemplateConfig();</span><br><span class="line">        tc.setController(<span class="string">"/template/controller.java.vm"</span>);</span><br><span class="line">        tc.setEntity(<span class="string">"/template/Entity.java.vm"</span>);</span><br><span class="line">        tc.setMapper(<span class="string">"/template/mapper.java.vm"</span>);</span><br><span class="line">        tc.setXml(<span class="string">"/template/mapper.xml.vm"</span>);</span><br><span class="line">        tc.setService(<span class="string">"/template/service.java.vm"</span>);</span><br><span class="line">        tc.setServiceImpl(<span class="string">"/template/serviceImpl.java.vm"</span>);</span><br><span class="line">        <span class="comment">// 如上任何一个模块如果设置 空 OR Null 将不生成该模块。</span></span><br><span class="line">        mpg.setTemplate(tc);</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 执行生成</span></span><br><span class="line">        mpg.execute();</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 打印注入设置【可无】</span></span><br><span class="line">        System.err.println(mpg.getCfg().getMap().get(<span class="string">"abc"</span>));</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="以下是我根据自身使用场景自定义的几个模板"><a href="#以下是我根据自身使用场景自定义的几个模板" class="headerlink" title="以下是我根据自身使用场景自定义的几个模板"></a>以下是我根据自身使用场景自定义的几个模板</h3><h4 id="controller-java-vm"><a href="#controller-java-vm" class="headerlink" title="controller.java.vm"></a>controller.java.vm</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> $&#123;<span class="keyword">package</span>.Controller&#125;;</span><br><span class="line">#if($&#123;superControllerClassPackage&#125;)</span><br><span class="line"><span class="keyword">import</span> $&#123;superControllerClassPackage&#125;;</span><br><span class="line">#end</span><br><span class="line"><span class="keyword">import</span> $&#123;<span class="keyword">package</span>.Entity&#125;.$&#123;entity&#125;;</span><br><span class="line"><span class="keyword">import</span> $&#123;<span class="keyword">package</span>.Service&#125;.$&#123;table.serviceName&#125;;</span><br><span class="line"><span class="keyword">import</span> org.springframework.beans.factory.annotation.Autowired;</span><br><span class="line"><span class="keyword">import</span> org.apache.shiro.authz.annotation.RequiresPermissions;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.bind.annotation.*;</span><br><span class="line"><span class="keyword">import</span> io.swagger.annotations.*;</span><br><span class="line"><span class="keyword">import</span> springfox.documentation.annotations.ApiIgnore;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> javax.servlet.http.HttpServletRequest;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.alibaba.fastjson.JSONObject;</span><br><span class="line"><span class="keyword">import</span> com.family.util.CommonUtil;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 版权所有: 版权所有© 2018-2020</span></span><br><span class="line"><span class="comment"> * 公 司: xxxx有限公司</span></span><br><span class="line"><span class="comment"> * 内容摘要: 无</span></span><br><span class="line"><span class="comment"> * 其他说明:无</span></span><br><span class="line"><span class="comment"> * 完成日期： $&#123;date&#125;</span></span><br><span class="line"><span class="comment"> * 修改记录: 无</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@version</span> 版本号</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> $&#123;author&#125;</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@RestController</span></span><br><span class="line"><span class="meta">@RequestMapping</span>(<span class="string">"#if($&#123;package.ModuleName&#125;)/$&#123;package.ModuleName&#125;#end/$&#123;table.entityPath&#125;"</span>)</span><br><span class="line">#if($&#123;superControllerClass&#125;)</span><br><span class="line"><span class="meta">@Api</span>(value = <span class="string">"$&#123;table.comment&#125;接口"</span>, description = <span class="string">"$&#123;table.comment&#125;"</span>)</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> $</span>&#123;table.controllerName&#125; extends$&#123;superControllerClass&#125;&lt;$&#123;entity&#125;&gt; &#123;</span><br><span class="line">#else</span><br><span class="line"><span class="meta">@Api</span>(value = <span class="string">"$&#123;table.comment&#125;接口"</span>, description = <span class="string">"$&#123;table.comment&#125;"</span>)</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> $</span>&#123;table.controllerName&#125; &#123;</span><br><span class="line">#end</span><br><span class="line"></span><br><span class="line">#foreach($field in $&#123;table.fields&#125;)</span><br><span class="line">    #if($&#123;field.keyFlag&#125;)</span><br><span class="line">        #set($keyPropertyName=$&#123;field.propertyName&#125;)</span><br><span class="line">        #set($keyPropertyAttr=$&#123;field.propertyType&#125;)</span><br><span class="line">    #end</span><br><span class="line">#end</span><br><span class="line"></span><br><span class="line">#set ($servicePropertyName = $table.serviceName.substring(0,1).toLowerCase() + $table.serviceName.substring(1,$table.serviceName.length()))</span><br><span class="line">#set ($classname = $entity.substring(0,1).toLowerCase() + $entity.substring(1,$entity.length()))</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> $&#123;table.serviceName&#125; $&#123;servicePropertyName&#125;;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 列表</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="meta">@GetMapping</span>(<span class="string">"/list"</span>)</span><br><span class="line">    <span class="meta">@RequiresPermissions</span>(<span class="string">"#if($&#123;package.ModuleName&#125;)#end$&#123;table.entityPath&#125;:list"</span>)</span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"$&#123;table.comment&#125;"</span>, notes = <span class="string">"获取$&#123;table.comment&#125;列表"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> JSONObject <span class="title">list</span><span class="params">(HttpServletRequest request)</span></span>&#123;</span><br><span class="line">        <span class="comment">//查询列表数据</span></span><br><span class="line">        <span class="keyword">return</span> $&#123;servicePropertyName&#125;.list(CommonUtil.request2Json(request));</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 信息</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="meta">@PostMapping</span>(<span class="string">"/info"</span>)</span><br><span class="line">    <span class="meta">@RequiresPermissions</span>(<span class="string">"#if($&#123;package.ModuleName&#125;)#end$&#123;table.entityPath&#125;:info"</span>)</span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"$&#123;table.comment&#125;"</span>, notes = <span class="string">"获取$&#123;table.comment&#125;详情信息"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> JSONObject <span class="title">info</span><span class="params">(@RequestBody JSONObject requestJson)</span></span>&#123;</span><br><span class="line">        CommonUtil.hasAllRequired(requestJson, <span class="string">"id"</span>);</span><br><span class="line">		<span class="keyword">return</span> $&#123;servicePropertyName&#125;.selectDetailsById(requestJson);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 保存</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="meta">@PostMapping</span>(<span class="string">"/save"</span>)</span><br><span class="line">    <span class="meta">@RequiresPermissions</span>(<span class="string">"#if($&#123;package.ModuleName&#125;)#end$&#123;table.entityPath&#125;:save"</span>)</span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"$&#123;table.comment&#125;"</span>, notes = <span class="string">"保存$&#123;table.comment&#125;信息"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> JSONObject <span class="title">save</span><span class="params">(@RequestBody $&#123;entity&#125; $&#123;classname&#125;)</span></span>&#123;</span><br><span class="line">        JSONObject jsonObject = CommonUtil.entityToJson($&#123;classname&#125;);</span><br><span class="line">		CommonUtil.hasAllRequired(jsonObject, <span class="string">""</span>);</span><br><span class="line">		<span class="keyword">return</span> $&#123;servicePropertyName&#125;.add$&#123;entity&#125;(jsonObject);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 修改</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="meta">@PostMapping</span>(<span class="string">"/update"</span>)</span><br><span class="line">    <span class="meta">@RequiresPermissions</span>(<span class="string">"#if($&#123;package.ModuleName&#125;)#end$&#123;table.entityPath&#125;:update"</span>)</span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"$&#123;table.comment&#125;"</span>, notes = <span class="string">"更新$&#123;table.comment&#125;信息"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> JSONObject <span class="title">update</span><span class="params">(@RequestBody JSONObject requestJson)</span></span>&#123;</span><br><span class="line">		CommonUtil.hasAllRequired(requestJson, <span class="string">"id"</span>);</span><br><span class="line">		<span class="keyword">return</span> $&#123;servicePropertyName&#125;.update$&#123;entity&#125;(requestJson);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 删除</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="meta">@PostMapping</span>(<span class="string">"/delete"</span>)</span><br><span class="line">    <span class="meta">@RequiresPermissions</span>(<span class="string">"#if($&#123;package.ModuleName&#125;)#end$&#123;table.entityPath&#125;:delete"</span>)</span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"$&#123;table.comment&#125;"</span>, notes = <span class="string">"删除$&#123;table.comment&#125;信息"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> JSONObject <span class="title">delete</span><span class="params">(@RequestBody JSONObject requestJson)</span></span>&#123;</span><br><span class="line">        CommonUtil.hasAllRequired(requestJson, <span class="string">"id"</span>);</span><br><span class="line">		<span class="keyword">return</span> $&#123;servicePropertyName&#125;.delete$&#123;entity&#125;(requestJson);</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="Entity-java-vm"><a href="#Entity-java-vm" class="headerlink" title="Entity.java.vm"></a>Entity.java.vm</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> $&#123;<span class="keyword">package</span>.Entity&#125;;</span><br><span class="line"></span><br><span class="line">#if($&#123;activeRecord&#125;)</span><br><span class="line"><span class="comment">/*import com.baomidou.mybatisplus.activerecord.Model;*/</span></span><br><span class="line">#end</span><br><span class="line">#foreach($pkg in $&#123;table.importPackages&#125;)</span><br><span class="line"><span class="keyword">import</span> $&#123;pkg&#125;;</span><br><span class="line">#end</span><br><span class="line"><span class="keyword">import</span> io.swagger.annotations.ApiModel;</span><br><span class="line"><span class="keyword">import</span> io.swagger.annotations.ApiModelProperty;</span><br><span class="line"><span class="keyword">import</span> com.fasterxml.jackson.annotation.JsonIgnore;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 文件名称: $&#123;table.comment&#125;实体类</span></span><br><span class="line"><span class="comment"> * 文件描述: $&#123;table.comment&#125;实体类</span></span><br><span class="line"><span class="comment"> * 版权所有: 版权所有© 2018-2020</span></span><br><span class="line"><span class="comment"> * 公 司: xxxx有限公司</span></span><br><span class="line"><span class="comment"> * 内容摘要: 无</span></span><br><span class="line"><span class="comment"> * 其他说明:无</span></span><br><span class="line"><span class="comment"> * 完成日期： $&#123;date&#125;</span></span><br><span class="line"><span class="comment"> * 修改记录: 无</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@version</span> 版本号</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> $&#123;author&#125;</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line">#if($&#123;table.convert&#125;)</span><br><span class="line"><span class="meta">@TableName</span>(<span class="string">"$&#123;table.name&#125;"</span>)</span><br><span class="line"><span class="meta">@ApiModel</span>(description=<span class="string">"$&#123;table.comment&#125; $&#123;entity&#125;"</span>)</span><br><span class="line">#end</span><br><span class="line">#if($&#123;superEntityClass&#125;)</span><br><span class="line">public class $&#123;entity&#125; extends $&#123;superEntityClass&#125;#if($&#123;activeRecord&#125;)&lt;$&#123;entity&#125;&gt;#end &#123;</span><br><span class="line">#elseif($&#123;activeRecord&#125;)</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> $</span>&#123;entity&#125; &#123;</span><br><span class="line">#else</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> $</span>&#123;entity&#125; implements Serializable &#123;</span><br><span class="line">#end</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="keyword">long</span> serialVersionUID = <span class="number">1L</span>;</span><br><span class="line"></span><br><span class="line">#foreach($field in $&#123;table.fields&#125;)</span><br><span class="line">#if($&#123;field.keyFlag&#125;)</span><br><span class="line">#set($keyPropertyName=$&#123;field.propertyName&#125;)</span><br><span class="line">	<span class="meta">@ApiModelProperty</span>(value=<span class="string">"主键$&#123;keyPropertyName&#125;"</span>,hidden=<span class="keyword">true</span>)</span><br><span class="line">#end</span><br><span class="line">#if("$!field.comment" != "")</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * $&#123;field.comment&#125;</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">#if($&#123;field.name&#125; == "delete_status" || $&#123;field.name&#125; == "update_time" || $&#123;field.name&#125; == "update_by")</span><br><span class="line">    <span class="meta">@ApiModelProperty</span>(value=<span class="string">"$&#123;field.comment&#125;"</span>,hidden=<span class="keyword">true</span>)</span><br><span class="line">#else</span><br><span class="line">	<span class="meta">@ApiModelProperty</span>(value=<span class="string">"$&#123;field.comment&#125;"</span>)</span><br><span class="line">#end</span><br><span class="line">#end</span><br><span class="line">#if($&#123;field.convert&#125;)</span><br><span class="line">#if($&#123;field.keyFlag&#125;)</span><br><span class="line">	<span class="meta">@TableId</span>(<span class="string">"$&#123;field.name&#125;"</span>)</span><br><span class="line">#else</span><br><span class="line">	<span class="meta">@TableField</span>(<span class="string">"$&#123;field.name&#125;"</span>)</span><br><span class="line">#end</span><br><span class="line">#end</span><br><span class="line">	<span class="keyword">private</span> $&#123;field.propertyType&#125; $&#123;field.propertyName&#125;;</span><br><span class="line">#end</span><br><span class="line"></span><br><span class="line">#foreach($field in $&#123;table.fields&#125;)</span><br><span class="line">#if($&#123;field.propertyType.equals("Boolean")&#125;)</span><br><span class="line">#set($getprefix="is")</span><br><span class="line">#else</span><br><span class="line">#set($getprefix="get")</span><br><span class="line">#end</span><br><span class="line">#if($&#123;field.capitalName&#125; == "DeleteStatus")</span><br><span class="line">	<span class="meta">@JsonIgnore</span></span><br><span class="line">	<span class="keyword">public</span> $&#123;field.propertyType&#125; $&#123;getprefix&#125;$&#123;field.capitalName&#125;() &#123;</span><br><span class="line">		<span class="keyword">return</span> $&#123;field.propertyName&#125;;</span><br><span class="line">	&#125;</span><br><span class="line">#else</span><br><span class="line">	<span class="keyword">public</span> $&#123;field.propertyType&#125; $&#123;getprefix&#125;$&#123;field.capitalName&#125;() &#123;</span><br><span class="line">		<span class="keyword">return</span> $&#123;field.propertyName&#125;;</span><br><span class="line">	&#125;</span><br><span class="line">#end</span><br><span class="line">#if($&#123;entityBuliderModel&#125;)</span><br><span class="line">	<span class="keyword">public</span> $&#123;entity&#125; set$&#123;field.capitalName&#125;($&#123;field.propertyType&#125; $&#123;field.propertyName&#125;) &#123;</span><br><span class="line">#else</span><br><span class="line">	<span class="keyword">public</span> <span class="keyword">void</span> set$&#123;field.capitalName&#125;($&#123;field.propertyType&#125; $&#123;field.propertyName&#125;) &#123;</span><br><span class="line">#end</span><br><span class="line">		<span class="keyword">this</span>.$&#123;field.propertyName&#125; = $&#123;field.propertyName&#125;;</span><br><span class="line">#if($&#123;entityBuliderModel&#125;)</span><br><span class="line">		<span class="keyword">return</span> <span class="keyword">this</span>;</span><br><span class="line">#end</span><br><span class="line">	&#125;</span><br><span class="line">#end</span><br><span class="line"></span><br><span class="line">#if($&#123;entityColumnConstant&#125;)</span><br><span class="line">#foreach($field in $&#123;table.fields&#125;)</span><br><span class="line">	<span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">final</span> String $&#123;field.name.toUpperCase()&#125; = <span class="string">"$&#123;field.name&#125;"</span>;</span><br><span class="line"></span><br><span class="line">#end</span><br><span class="line">#end</span><br><span class="line">#if($&#123;activeRecord&#125;)</span><br><span class="line">	<span class="function"><span class="keyword">protected</span> Serializable <span class="title">pkVal</span><span class="params">()</span> </span>&#123;</span><br><span class="line">#if($&#123;keyPropertyName&#125;)</span><br><span class="line">		<span class="keyword">return</span> <span class="keyword">this</span>.$&#123;keyPropertyName&#125;;</span><br><span class="line">#else</span><br><span class="line">		<span class="keyword">return</span> <span class="keyword">this</span>.id;</span><br><span class="line">#end</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">#end</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="mapper-java-vm"><a href="#mapper-java-vm" class="headerlink" title="mapper.java.vm"></a>mapper.java.vm</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> $&#123;<span class="keyword">package</span>.Mapper&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> $&#123;<span class="keyword">package</span>.Entity&#125;.$&#123;entity&#125;;</span><br><span class="line"><span class="keyword">import</span> com.alibaba.fastjson.JSONObject;</span><br><span class="line"><span class="keyword">import</span> org.apache.ibatis.annotations.Mapper;</span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 文件名称: $&#123;table.comment&#125; Mapper 接口</span></span><br><span class="line"><span class="comment"> * 文件描述: $&#123;table.comment&#125; Mapper 接口</span></span><br><span class="line"><span class="comment"> * 版权所有: 版权所有© 2018-2020</span></span><br><span class="line"><span class="comment"> * 公 司: xxxx有限公司</span></span><br><span class="line"><span class="comment"> * 内容摘要: 无</span></span><br><span class="line"><span class="comment"> * 其他说明:无</span></span><br><span class="line"><span class="comment"> * 完成日期： $&#123;date&#125;</span></span><br><span class="line"><span class="comment"> * 修改记录: 无</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@version</span> 版本号</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> $&#123;author&#125;</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Mapper</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> $</span>&#123;table.mapperName&#125; &#123;</span><br><span class="line"></span><br><span class="line">	<span class="function"><span class="keyword">int</span> <span class="title">insert</span><span class="params">(JSONObject jsonObject)</span></span>;</span><br><span class="line"></span><br><span class="line">	<span class="function"><span class="keyword">int</span> <span class="title">countArticle</span><span class="params">(JSONObject jsonObject)</span></span>;</span><br><span class="line"></span><br><span class="line">	List&lt;JSONObject&gt; list$&#123;entity&#125;(JSONObject jsonObject);</span><br><span class="line">	</span><br><span class="line">	<span class="function"><span class="keyword">int</span> <span class="title">updateByPrimaryKeySelective</span><span class="params">(JSONObject jsonObject)</span></span>;</span><br><span class="line">	</span><br><span class="line">	<span class="keyword">int</span> delete$&#123;entity&#125;ById(JSONObject jsonObject);</span><br><span class="line">	</span><br><span class="line">	$&#123;entity&#125; selectDetailsById(JSONObject requestJson);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="mapper-xml-vm"><a href="#mapper-xml-vm" class="headerlink" title="mapper.xml.vm"></a>mapper.xml.vm</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span><br><span class="line">&lt;!DOCTYPE mapper PUBLIC &quot;-//mybatis.org//DTD Mapper 3.0//EN&quot; &quot;http://mybatis.org/dtd/mybatis-3-mapper.dtd&quot;&gt;</span><br><span class="line">&lt;mapper namespace=&quot;$&#123;package.Mapper&#125;.$&#123;table.mapperName&#125;&quot;&gt;</span><br><span class="line"></span><br><span class="line">#if($&#123;enableCache&#125;)</span><br><span class="line">    &lt;!-- 开启二级缓存 --&gt;</span><br><span class="line">    &lt;cache type=&quot;org.mybatis.caches.ehcache.LoggingEhcache&quot;/&gt;</span><br><span class="line"></span><br><span class="line">#end</span><br><span class="line">#if($&#123;baseResultMap&#125;)</span><br><span class="line">    &lt;!-- 通用查询映射结果 --&gt;</span><br><span class="line">    &lt;resultMap id=&quot;BaseResultMap&quot; type=&quot;$&#123;package.Entity&#125;.$&#123;entity&#125;&quot;&gt;</span><br><span class="line">#foreach($field in $&#123;table.fields&#125;)</span><br><span class="line">#if($&#123;field.keyFlag&#125;)##生成主键排在第一位</span><br><span class="line">        &lt;id column=&quot;$&#123;field.name&#125;&quot; property=&quot;$&#123;field.propertyName&#125;&quot; /&gt;</span><br><span class="line">#end</span><br><span class="line">#end</span><br><span class="line">#foreach($field in $&#123;table.commonFields&#125;)##生成公共字段</span><br><span class="line">    &lt;result column=&quot;$&#123;field.name&#125;&quot; property=&quot;$&#123;field.propertyName&#125;&quot; /&gt;</span><br><span class="line">#end</span><br><span class="line">#foreach($field in $&#123;table.fields&#125;)</span><br><span class="line">#if(!$&#123;field.keyFlag&#125;)##生成普通字段</span><br><span class="line">        &lt;result column=&quot;$&#123;field.name&#125;&quot; property=&quot;$&#123;field.propertyName&#125;&quot; /&gt;</span><br><span class="line">#end</span><br><span class="line">#end</span><br><span class="line">    &lt;/resultMap&gt;</span><br><span class="line"></span><br><span class="line">#end</span><br><span class="line">#if($&#123;baseColumnList&#125;)</span><br><span class="line">    &lt;!-- 通用查询结果列 --&gt;</span><br><span class="line">    &lt;sql id=&quot;Base_Column_List&quot;&gt;</span><br><span class="line">#foreach($field in $&#123;table.commonFields&#125;)</span><br><span class="line">        $&#123;field.name&#125;,</span><br><span class="line">#end</span><br><span class="line">        $&#123;table.fieldNames&#125;</span><br><span class="line">    &lt;/sql&gt;</span><br><span class="line"></span><br><span class="line">#end</span><br><span class="line">  &lt;!-- 有效数据总条数查询 --&gt;</span><br><span class="line">  &lt;select id=&quot;countArticle&quot; resultType=&quot;Integer&quot;&gt;</span><br><span class="line">     select count(0) from $&#123;table.name&#125; where delete_status = &apos;1&apos; </span><br><span class="line">  &lt;/select&gt;</span><br><span class="line">  </span><br><span class="line">  &lt;!-- 带分页列表查询 --&gt;</span><br><span class="line">  &lt;select id=&quot;list$&#123;entity&#125;&quot; resultMap=&quot;BaseResultMap&quot; resultType=&quot;com.alibaba.fastjson.JSONObject&quot;&gt;</span><br><span class="line">    select  &lt;include refid=&quot;Base_Column_List&quot; /&gt;  from $&#123;table.name&#125;  </span><br><span class="line">    where delete_status = &apos;1&apos; ORDER BY create_time DESC LIMIT #&#123;offSet&#125;, #&#123;pageRow&#125;</span><br><span class="line">  &lt;/select&gt;</span><br><span class="line">  </span><br><span class="line">  &lt;!-- 根据主键id查询$&#123;table.name&#125;详细信息 --&gt;</span><br><span class="line">  &lt;select id=&quot;selectDetailsById&quot; resultMap=&quot;BaseResultMap&quot; resultType=&quot;com.alibaba.fastjson.JSONObject&quot;&gt;</span><br><span class="line">    select  &lt;include refid=&quot;Base_Column_List&quot; /&gt;  from $&#123;table.name&#125;  where delete_status = &apos;1&apos; and id = #&#123;id,jdbcType=BIGINT&#125;</span><br><span class="line">  &lt;/select&gt;</span><br><span class="line">  </span><br><span class="line">  &lt;!-- 新增 --&gt;</span><br><span class="line">    &lt;insert id=&quot;insert&quot;&gt;</span><br><span class="line">    insert into $&#123;table.name&#125; </span><br><span class="line">(#foreach($field in $&#123;table.fields&#125;)</span><br><span class="line">#if($&#123;field.keyFlag&#125;)##生成主键排在第一位</span><br><span class="line">  $&#123;field.name&#125;#if($foreach.hasNext),#end</span><br><span class="line">#end</span><br><span class="line">#end</span><br><span class="line">#foreach($field in $&#123;table.commonFields&#125;)##生成公共字段</span><br><span class="line">  $&#123;field.name&#125;#if($foreach.hasNext),#end</span><br><span class="line">#end</span><br><span class="line">#foreach($field in $&#123;table.fields&#125;)</span><br><span class="line">#if(!$&#123;field.keyFlag&#125;)##生成普通字段</span><br><span class="line">  $&#123;field.name&#125;#if($foreach.hasNext),#end</span><br><span class="line">#end</span><br><span class="line">#end)</span><br><span class="line">    values (</span><br><span class="line">#foreach($field in $&#123;table.fields&#125;)</span><br><span class="line">#if($&#123;field.keyFlag&#125;)##生成主键排在第一位</span><br><span class="line">  #&#123;$&#123;field.propertyName&#125;&#125;#if($foreach.hasNext),#end</span><br><span class="line">#end</span><br><span class="line">#end</span><br><span class="line">#foreach($field in $&#123;table.commonFields&#125;)##生成公共字段</span><br><span class="line">  #&#123;$&#123;field.propertyName&#125;&#125;#if($foreach.hasNext),#end</span><br><span class="line">#end</span><br><span class="line">#foreach($field in $&#123;table.fields&#125;)</span><br><span class="line">#if(!$&#123;field.keyFlag&#125;)##生成普通字段</span><br><span class="line">  #&#123;$&#123;field.propertyName&#125;&#125;#if($foreach.hasNext),#end</span><br><span class="line">#end</span><br><span class="line">#end)</span><br><span class="line">  &lt;/insert&gt;</span><br><span class="line">  </span><br><span class="line">  &lt;!-- 修改 --&gt;</span><br><span class="line">  &lt;update id=&quot;updateByPrimaryKeySelective&quot;&gt;</span><br><span class="line">    update $&#123;table.name&#125; </span><br><span class="line">    &lt;set&gt;</span><br><span class="line"> #foreach($field in $&#123;table.fields&#125;)</span><br><span class="line"> #if(!$&#123;field.keyFlag&#125;)##生成普通字段</span><br><span class="line">	&lt;if test=&quot;$&#123;field.propertyName&#125; != null&quot; &gt;</span><br><span class="line">		$&#123;field.name&#125; = #&#123;$&#123;field.propertyName&#125;&#125;,</span><br><span class="line">	&lt;/if&gt;</span><br><span class="line"> #end</span><br><span class="line"> #end</span><br><span class="line">    &lt;/set&gt;</span><br><span class="line">    where id = #&#123;id,jdbcType=BIGINT&#125;</span><br><span class="line">  &lt;/update&gt;</span><br><span class="line">  </span><br><span class="line">  &lt;!-- 逻辑删除 --&gt;</span><br><span class="line">  &lt;update id=&quot;delete$&#123;entity&#125;ById&quot;&gt;</span><br><span class="line">    update $&#123;table.name&#125; set delete_status = 2 where id = #&#123;id,jdbcType=BIGINT&#125;</span><br><span class="line">  &lt;/update&gt;</span><br><span class="line">  </span><br><span class="line">&lt;/mapper&gt;</span><br></pre></td></tr></table></figure>
<h4 id="service-java-vm"><a href="#service-java-vm" class="headerlink" title="service.java.vm"></a>service.java.vm</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">package $&#123;package.Service&#125;;</span><br><span class="line">import $&#123;package.Entity&#125;.$&#123;entity&#125;;</span><br><span class="line">import com.alibaba.fastjson.JSONObject;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * 文件名称: $&#123;table.comment&#125; 服务接口</span><br><span class="line"> * 文件描述: $&#123;table.comment&#125; 服务接口</span><br><span class="line"> * 版权所有: 版权所有© 2018-2020</span><br><span class="line"> * 公 司: xxxx有限公司</span><br><span class="line"> * 内容摘要: 无</span><br><span class="line"> * 其他说明:无</span><br><span class="line"> * 完成日期： $&#123;date&#125;</span><br><span class="line"> * 修改记录: 无</span><br><span class="line"> * @version 产品版本</span><br><span class="line"> * @author $&#123;author&#125;</span><br><span class="line"> */</span><br><span class="line">public interface $&#123;table.serviceName&#125; &#123;</span><br><span class="line">	</span><br><span class="line">	JSONObject list(JSONObject requestJson);</span><br><span class="line"></span><br><span class="line">	JSONObject selectDetailsById(JSONObject requestJson);</span><br><span class="line">	</span><br><span class="line">	JSONObject add$&#123;entity&#125;(JSONObject requestJson);</span><br><span class="line">	</span><br><span class="line">	JSONObject update$&#123;entity&#125;(JSONObject requestJson);</span><br><span class="line">	</span><br><span class="line">	JSONObject delete$&#123;entity&#125;(JSONObject requestJson);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="serviceImpl-java-vm"><a href="#serviceImpl-java-vm" class="headerlink" title="serviceImpl.java.vm"></a>serviceImpl.java.vm</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br></pre></td><td class="code"><pre><span class="line">package $&#123;package.ServiceImpl&#125;;</span><br><span class="line">import $&#123;package.Entity&#125;.$&#123;entity&#125;;</span><br><span class="line">import $&#123;package.Mapper&#125;.$&#123;table.mapperName&#125;;</span><br><span class="line">import $&#123;package.Service&#125;.$&#123;table.serviceName&#125;;</span><br><span class="line">import org.springframework.stereotype.Service;</span><br><span class="line">import org.springframework.transaction.annotation.Transactional;</span><br><span class="line">import org.springframework.beans.factory.annotation.Autowired;</span><br><span class="line"></span><br><span class="line">import com.family.util.CommonUtil;</span><br><span class="line">import com.alibaba.fastjson.JSONObject;</span><br><span class="line">import java.util.List;</span><br><span class="line">import java.util.Date;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * 文件名称: $&#123;table.comment&#125; 服务接口实现类</span><br><span class="line"> * 文件描述: $&#123;table.comment&#125; 服务接口实现类</span><br><span class="line"> * 版权所有: 版权所有© 2018-2020</span><br><span class="line"> * 公 司: xxxx有限公司</span><br><span class="line"> * 内容摘要: 无</span><br><span class="line"> * 其他说明:无</span><br><span class="line"> * 完成日期： $&#123;date&#125;</span><br><span class="line"> * 修改记录: 无</span><br><span class="line"> * @version 产品版本</span><br><span class="line"> * @author $&#123;author&#125;</span><br><span class="line"> */</span><br><span class="line">@Service</span><br><span class="line">@Transactional</span><br><span class="line">public class $&#123;table.serviceImplName&#125; implements $&#123;table.serviceName&#125; &#123;</span><br><span class="line">	</span><br><span class="line">	@Autowired</span><br><span class="line">	#set ($mapperPropertyName = $table.mapperName.substring(0,1).toLowerCase() + $table.mapperName.substring(1,$table.mapperName.length()))</span><br><span class="line">	private $&#123;table.mapperName&#125; $&#123;mapperPropertyName&#125;;</span><br><span class="line">	</span><br><span class="line">	/**</span><br><span class="line">	 * 接口名称: $&#123;table.comment&#125;带分页的列表查询</span><br><span class="line">	 * 内容摘要: 获取一个带分页的$&#123;table.comment&#125;列表，然后返回一个json</span><br><span class="line">	 * 其他说明:无</span><br><span class="line">	 */</span><br><span class="line">	@Override</span><br><span class="line">	public JSONObject list(JSONObject jsonObject) &#123;</span><br><span class="line">		CommonUtil.fillPageParam(jsonObject);</span><br><span class="line">        int count = $&#123;mapperPropertyName&#125;.countArticle(jsonObject);</span><br><span class="line">        List&lt;JSONObject&gt; list = $&#123;mapperPropertyName&#125;.list$&#123;entity&#125;(jsonObject);</span><br><span class="line">		return CommonUtil.successPage(jsonObject, list, count);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	/**</span><br><span class="line">	 * 接口名称: 新增一条$&#123;table.comment&#125;数据</span><br><span class="line">	 * 内容摘要: 新增一条$&#123;table.comment&#125;数据，新增成功后把提交的数据转化为json然后返回</span><br><span class="line">	 * 其他说明:无</span><br><span class="line">	 */</span><br><span class="line">	@Override</span><br><span class="line">	public JSONObject add$&#123;entity&#125;(JSONObject jsonObject) &#123;</span><br><span class="line">		jsonObject.put(&quot;createTime&quot;, new Date());</span><br><span class="line">		$&#123;mapperPropertyName&#125;.insert(jsonObject);</span><br><span class="line">    	return CommonUtil.successJson(jsonObject);</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	/**</span><br><span class="line">	 * 接口名称: 根据主键id修改$&#123;table.comment&#125;数据</span><br><span class="line">	 * 内容摘要: 根据主键id修改$&#123;table.comment&#125;数据，修改成功后把提交的数据转化为json然后返回</span><br><span class="line">	 * 其他说明:无</span><br><span class="line">	 */</span><br><span class="line">	@Override</span><br><span class="line">	public JSONObject update$&#123;entity&#125;(JSONObject jsonObject) &#123;</span><br><span class="line">		jsonObject.put(&quot;updateTime&quot;, new Date());</span><br><span class="line">		$&#123;mapperPropertyName&#125;.updateByPrimaryKeySelective(jsonObject);</span><br><span class="line">    	return CommonUtil.successJson(jsonObject);</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	/**</span><br><span class="line">	 * 接口名称: 根据主键id逻辑删除$&#123;table.comment&#125;数据</span><br><span class="line">	 * 内容摘要: 根据主键id逻辑删除$&#123;table.comment&#125;数据，删除成功后把提交的数据转化为json然后返回</span><br><span class="line">	 * 其他说明:无</span><br><span class="line">	 */</span><br><span class="line">	@Override</span><br><span class="line">	public JSONObject delete$&#123;entity&#125;(JSONObject jsonObject) &#123;</span><br><span class="line">		$&#123;mapperPropertyName&#125;.delete$&#123;entity&#125;ById(jsonObject);</span><br><span class="line">    	return CommonUtil.successJson(jsonObject);</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	/**</span><br><span class="line">	 * 接口名称: 根据主键id查看$&#123;table.comment&#125;详情</span><br><span class="line">	 * 内容摘要: 根据主键id查看$&#123;table.comment&#125;详情，成功后把提交的数据转化为json然后返回</span><br><span class="line">	 * 其他说明:无</span><br><span class="line">	 */</span><br><span class="line">	@Override</span><br><span class="line">	public JSONObject selectDetailsById(JSONObject jsonObject) &#123;</span><br><span class="line">		$&#123;entity&#125; $&#123;table.entityPath&#125; = $&#123;mapperPropertyName&#125;.selectDetailsById(jsonObject);</span><br><span class="line">    	return CommonUtil.successJson($&#123;table.entityPath&#125;);</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="既然都写了这么多了，索性把这套模板所对应的工具类一并给出，下面是工具类代码-CommonUtil-java："><a href="#既然都写了这么多了，索性把这套模板所对应的工具类一并给出，下面是工具类代码-CommonUtil-java：" class="headerlink" title="既然都写了这么多了，索性把这套模板所对应的工具类一并给出，下面是工具类代码 CommonUtil.java："></a>既然都写了这么多了，索性把这套模板所对应的工具类一并给出，下面是工具类代码 CommonUtil.java：</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.alibaba.fastjson.JSONObject;</span><br><span class="line"><span class="keyword">import</span> com.family.config.exception.CommonJsonException;</span><br><span class="line"><span class="keyword">import</span> com.family.util.constants.Constants;</span><br><span class="line"><span class="keyword">import</span> com.family.util.constants.ErrorEnum;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> javax.servlet.http.HttpServletRequest;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.Enumeration;</span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span>: cd</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@description</span>: 本后台接口系统常用的json工具类</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@date</span>: 2018/03/10 10:12</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">CommonUtil</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 返回一个returnData为空对象的成功消息的json</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> JSONObject <span class="title">successJson</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> successJson(<span class="keyword">new</span> JSONObject());</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 返回一个返回码为100的json</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> returnData json里的主要内容</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> JSONObject <span class="title">successJson</span><span class="params">(Object returnData)</span> </span>&#123;</span><br><span class="line">        JSONObject resultJson = <span class="keyword">new</span> JSONObject();</span><br><span class="line">        resultJson.put(<span class="string">"returnCode"</span>, Constants.SUCCESS_CODE);</span><br><span class="line">        resultJson.put(<span class="string">"returnMsg"</span>, Constants.SUCCESS_MSG);</span><br><span class="line">        resultJson.put(<span class="string">"returnData"</span>, returnData);</span><br><span class="line">        <span class="keyword">return</span> resultJson;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 返回错误信息JSON</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> errorEnum 错误码的errorEnum</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> JSONObject <span class="title">errorJson</span><span class="params">(ErrorEnum errorEnum)</span> </span>&#123;</span><br><span class="line">        JSONObject resultJson = <span class="keyword">new</span> JSONObject();</span><br><span class="line">        resultJson.put(<span class="string">"returnCode"</span>, errorEnum.getErrorCode());</span><br><span class="line">        resultJson.put(<span class="string">"returnMsg"</span>, errorEnum.getErrorMsg());</span><br><span class="line">        resultJson.put(<span class="string">"returnData"</span>, <span class="keyword">new</span> JSONObject());</span><br><span class="line">        <span class="keyword">return</span> resultJson;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 查询分页结果后的封装工具方法</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> requestJson 请求参数json,此json在之前调用fillPageParam 方法时,已经将pageRow放入</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> list        查询分页对象list</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> totalCount  查询出记录的总条数</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> JSONObject <span class="title">successPage</span><span class="params">(<span class="keyword">final</span> JSONObject requestJson, List&lt;JSONObject&gt; list, <span class="keyword">int</span> totalCount)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">int</span> pageRow = requestJson.getIntValue(<span class="string">"pageRow"</span>);</span><br><span class="line">        <span class="keyword">int</span> totalPage = getPageCounts(pageRow, totalCount);</span><br><span class="line">        JSONObject result = successJson();</span><br><span class="line">        JSONObject returnData = <span class="keyword">new</span> JSONObject();</span><br><span class="line">        returnData.put(<span class="string">"list"</span>, list);</span><br><span class="line">        returnData.put(<span class="string">"totalCount"</span>, totalCount);</span><br><span class="line">        returnData.put(<span class="string">"totalPage"</span>, totalPage);</span><br><span class="line">        result.put(<span class="string">"returnData"</span>, returnData);</span><br><span class="line">        <span class="keyword">return</span> result;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 查询分页结果后的封装工具方法</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> list 查询分页对象list</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> JSONObject <span class="title">successPage</span><span class="params">(List&lt;JSONObject&gt; list)</span> </span>&#123;</span><br><span class="line">        JSONObject result = successJson();</span><br><span class="line">        JSONObject returnData = <span class="keyword">new</span> JSONObject();</span><br><span class="line">        returnData.put(<span class="string">"list"</span>, list);</span><br><span class="line">        result.put(<span class="string">"returnData"</span>, returnData);</span><br><span class="line">        <span class="keyword">return</span> result;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 获取总页数</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> pageRow   每页行数</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> itemCount 结果的总条数</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">int</span> <span class="title">getPageCounts</span><span class="params">(<span class="keyword">int</span> pageRow, <span class="keyword">int</span> itemCount)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (itemCount == <span class="number">0</span>) &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="number">1</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> itemCount % pageRow &gt; <span class="number">0</span> ?</span><br><span class="line">                itemCount / pageRow + <span class="number">1</span> :</span><br><span class="line">                itemCount / pageRow;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 将request参数值转为json</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> request</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> JSONObject <span class="title">request2Json</span><span class="params">(HttpServletRequest request)</span> </span>&#123;</span><br><span class="line">        JSONObject requestJson = <span class="keyword">new</span> JSONObject();</span><br><span class="line">        Enumeration paramNames = request.getParameterNames();</span><br><span class="line">        <span class="keyword">while</span> (paramNames.hasMoreElements()) &#123;</span><br><span class="line">            String paramName = (String) paramNames.nextElement();</span><br><span class="line">            String[] pv = request.getParameterValues(paramName);</span><br><span class="line">            StringBuilder sb = <span class="keyword">new</span> StringBuilder();</span><br><span class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; pv.length; i++) &#123;</span><br><span class="line">                <span class="keyword">if</span> (pv[i].length() &gt; <span class="number">0</span>) &#123;</span><br><span class="line">                    <span class="keyword">if</span> (i &gt; <span class="number">0</span>) &#123;</span><br><span class="line">                        sb.append(<span class="string">","</span>);</span><br><span class="line">                    &#125;</span><br><span class="line">                    sb.append(pv[i]);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            requestJson.put(paramName, sb.toString());</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> requestJson;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 将request转JSON</span></span><br><span class="line"><span class="comment">     * 并且验证非空字段</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> request</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> requiredColumns</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> JSONObject <span class="title">convert2JsonAndCheckRequiredColumns</span><span class="params">(HttpServletRequest request, String requiredColumns)</span> </span>&#123;</span><br><span class="line">        JSONObject jsonObject = request2Json(request);</span><br><span class="line">        hasAllRequired(jsonObject, requiredColumns);</span><br><span class="line">        <span class="keyword">return</span> jsonObject;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 验证是否含有全部必填字段</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> requiredColumns 必填的参数字段名称 逗号隔开 比如"userId,name,telephone"</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> jsonObject</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">hasAllRequired</span><span class="params">(<span class="keyword">final</span> JSONObject jsonObject, String requiredColumns)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (!StringTools.isNullOrEmpty(requiredColumns)) &#123;</span><br><span class="line">            <span class="comment">//验证字段非空</span></span><br><span class="line">            String[] columns = requiredColumns.split(<span class="string">","</span>);</span><br><span class="line">            String missCol = <span class="string">""</span>;</span><br><span class="line">            <span class="keyword">for</span> (String column : columns) &#123;</span><br><span class="line">                Object val = jsonObject.get(column.trim());</span><br><span class="line">                <span class="keyword">if</span> (StringTools.isNullOrEmpty(val)) &#123;</span><br><span class="line">                    missCol += column + <span class="string">"  "</span>;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span> (!StringTools.isNullOrEmpty(missCol)) &#123;</span><br><span class="line">                jsonObject.clear();</span><br><span class="line">                jsonObject.put(<span class="string">"returnCode"</span>, ErrorEnum.E_90003.getErrorCode());</span><br><span class="line">                jsonObject.put(<span class="string">"returnMsg"</span>, <span class="string">"缺少必填参数:"</span> + missCol.trim());</span><br><span class="line">                jsonObject.put(<span class="string">"returnData"</span>, <span class="keyword">new</span> JSONObject());</span><br><span class="line">                <span class="keyword">throw</span> <span class="keyword">new</span> CommonJsonException(jsonObject);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 在分页查询之前,为查询条件里加上分页参数</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> paramObject    查询条件json</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> defaultPageRow 默认的每页条数,即前端不传pageRow参数时的每页条数</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">fillPageParam</span><span class="params">(<span class="keyword">final</span> JSONObject paramObject, <span class="keyword">int</span> defaultPageRow)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">int</span> pageNum = paramObject.getIntValue(<span class="string">"pageNum"</span>);</span><br><span class="line">        pageNum = pageNum == <span class="number">0</span> ? <span class="number">1</span> : pageNum;</span><br><span class="line">        <span class="keyword">int</span> pageRow = paramObject.getIntValue(<span class="string">"pageRow"</span>);</span><br><span class="line">        pageRow = pageRow == <span class="number">0</span> ? defaultPageRow : pageRow;</span><br><span class="line">        paramObject.put(<span class="string">"offSet"</span>, (pageNum - <span class="number">1</span>) * pageRow);</span><br><span class="line">        paramObject.put(<span class="string">"pageRow"</span>, pageRow);</span><br><span class="line">        paramObject.put(<span class="string">"pageNum"</span>, pageNum);</span><br><span class="line">        <span class="comment">//删除此参数,防止前端传了这个参数,pageHelper分页插件检测到之后,拦截导致SQL错误</span></span><br><span class="line">        paramObject.remove(<span class="string">"pageSize"</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 分页查询之前的处理参数</span></span><br><span class="line"><span class="comment">     * 没有传pageRow参数时,默认每页10条.</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> paramObject</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">fillPageParam</span><span class="params">(<span class="keyword">final</span> JSONObject paramObject)</span> </span>&#123;</span><br><span class="line">        fillPageParam(paramObject, <span class="number">14</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 实体类转json</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> object</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> JSONObject <span class="title">entityToJson</span><span class="params">(Object object)</span> </span>&#123;</span><br><span class="line">        String json = JSONObject.toJSONString(object);</span><br><span class="line">        JSONObject jsonObject = JSONObject.parseObject(json);</span><br><span class="line">        <span class="keyword">return</span> jsonObject;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="Constants-java"><a href="#Constants-java" class="headerlink" title="Constants.java"></a>Constants.java</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span>: cd</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@description</span>: 通用常量类, 单个业务的常量请单开一个类, 方便常量的分类管理</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@date</span>: 2018/03/10 10:15</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Constants</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">final</span> String SUCCESS_CODE = <span class="string">"100"</span>;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">final</span> String SUCCESS_MSG = <span class="string">"请求成功"</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * session中存放用户信息的key值</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">final</span> String SESSION_USER_INFO = <span class="string">"userInfo"</span>;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">final</span> String SESSION_USER_PERMISSION = <span class="string">"userPermission"</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="ErrorEnum-java"><a href="#ErrorEnum-java" class="headerlink" title="ErrorEnum.java"></a>ErrorEnum.java</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span>: cd</span></span><br><span class="line"><span class="comment"> * 错误信息封装</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@date</span>: 2018/03/10 10:16</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">enum</span> ErrorEnum &#123;</span><br><span class="line"></span><br><span class="line">    E_400(<span class="string">"400"</span>, <span class="string">"请求处理异常，请稍后再试"</span>),</span><br><span class="line">    </span><br><span class="line">    E_500(<span class="string">"500"</span>, <span class="string">"请求方式有误,请检查 GET/POST"</span>),</span><br><span class="line">    </span><br><span class="line">    E_501(<span class="string">"501"</span>, <span class="string">"请求路径不存在"</span>),</span><br><span class="line">    </span><br><span class="line">    E_502(<span class="string">"502"</span>, <span class="string">"权限不足"</span>),</span><br><span class="line">    </span><br><span class="line">    E_10008(<span class="string">"10008"</span>, <span class="string">"角色删除失败,尚有用户属于此角色"</span>),</span><br><span class="line">    </span><br><span class="line">    E_10009(<span class="string">"10009"</span>, <span class="string">"账户已存在"</span>),</span><br><span class="line">    </span><br><span class="line">    E_10010(<span class="string">"10010"</span>, <span class="string">"该手机号已存在"</span>),</span><br><span class="line"></span><br><span class="line">    E_20011(<span class="string">"20011"</span>, <span class="string">"登陆已过期,请重新登陆"</span>),</span><br><span class="line"></span><br><span class="line">    E_90003(<span class="string">"90003"</span>, <span class="string">"缺少必填参数"</span>),</span><br><span class="line"></span><br><span class="line">    E_90005(<span class="string">"90004"</span>, <span class="string">"请求参数有误"</span>),</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> String errorCode;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> String errorMsg;</span><br><span class="line"></span><br><span class="line">    ErrorEnum() &#123;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    ErrorEnum(String errorCode, String errorMsg) &#123;</span><br><span class="line">        <span class="keyword">this</span>.errorCode = errorCode;</span><br><span class="line">        <span class="keyword">this</span>.errorMsg = errorMsg;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getErrorCode</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> errorCode;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setErrorCode</span><span class="params">(String errorCode)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.errorCode = errorCode;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getErrorMsg</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> errorMsg;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setErrorMsg</span><span class="params">(String errorMsg)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.errorMsg = errorMsg;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="好了，全文到此结束，想要用的可以直接复制然后添加到项目中撸码不易，转载请标明出处，下一节讲spring-boot-mybatis-shiro-swagger实现前后端分离的架构搭建"><a href="#好了，全文到此结束，想要用的可以直接复制然后添加到项目中撸码不易，转载请标明出处，下一节讲spring-boot-mybatis-shiro-swagger实现前后端分离的架构搭建" class="headerlink" title="好了，全文到此结束，想要用的可以直接复制然后添加到项目中撸码不易，转载请标明出处，下一节讲spring boot + mybatis + shiro + swagger实现前后端分离的架构搭建"></a>好了，全文到此结束，想要用的可以直接复制然后添加到项目中撸码不易，转载请标明出处，下一节讲spring boot + mybatis + shiro + swagger实现前后端分离的架构搭建</h3>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://chinawfsl.gitee.io/blog/blog/2019/03/21/Hexo编写博客技巧/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="无名小卒">
      <meta itemprop="description" content>
      <meta itemprop="image" content="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1553150146014&di=dc4e5d4bdfbc647f7eca1367401dbc47&imgtype=0&src=http%3A%2F%2Fs9.knowsky.com%2Fbizhi%2Fl%2F20090606%2F200906186%2520%25281%2529.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="无名小卒">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2019/03/21/Hexo编写博客技巧/" itemprop="url">Hexo编写博客技巧</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-03-21T14:34:30+08:00">
                2019-03-21
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/操作说明/" itemprop="url" rel="index">
                    <span itemprop="name">操作说明</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h2 id="Hexo编写博客工具"><a href="#Hexo编写博客工具" class="headerlink" title="Hexo编写博客工具"></a>Hexo编写博客工具</h2><p>工具推荐使用Typora,<a href="https://liaichuan.top/2018/07/l8/程序员必备神S%EF%BC%8STypora%EF*BC紹9/" target="_blank" rel="noopener">程序员必备神器（Typora)</a>。你也可以使用Sublime Text 3来写，Sublime Text 3写的话需要写MD语法。我是使用的后者，诸位随意。</p>
<h2 id="Hexo在博文中插入图片"><a href="#Hexo在博文中插入图片" class="headerlink" title="Hexo在博文中插入图片"></a>Hexo在博文中插入图片</h2><p>-插入本地图片 -插入有链接的图片</p>
<h3 id="插入本地图片"><a href="#插入本地图片" class="headerlink" title="插入本地图片"></a>插入本地图片</h3><p>插入本地图片需要修改主题’ _conf ig.yml’配置文件’ post_asset_folder’项为’ true’。<br>使用插件达到插入本地图片，在根目录输入如下命令安装：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ npm install hexo-asset-image --save</span><br></pre></td></tr></table></figure></p>
<p>今后你new _篇博客时’/source/_posts’文件夹内除了 xxxx.mcT文件还有一个同名的文件夹，把图片放到里面即可.<img src="http://bmob-cdn-20430.b0.upaiyun.com/2018/07/20/d6bfd2a040c487af8072834dfa4d3388.png" alt>最后在’xxxx.md’中想引入图片时，先把图片复制到xxxx这个文件夹中，然后只需要在xxxx.md中按照markdown的格式引入图片：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">![你想输入的替代文字](xxxx/图片名.jpg)  注：[]内也可以不添加文字</span><br></pre></td></tr></table></figure></p>
<h3 id="插入有链接的图片"><a href="#插入有链接的图片" class="headerlink" title="插入有链接的图片"></a>插入有链接的图片</h3><p>考虑到本地存放图片图片，一占用电脑内存，二来博客项目过于膨大，想一下，一篇博客三四张图片，10篇20篇以后呢?所以我们不能只有一种对策方法，凡事都有三种对策方法才行。当然了， 本地图片也有好处，存放更换频繁的、重要的、隐私的图片最佳选择。使用第三方平台保存图片的话，推荐使用<a href="https://www.bmob.cn/" target="_blank" rel="noopener">Bmob</a>和<a href="https://www.qiniu.com/" target="_blank" rel="noopener">七牛云</a>+MPic,我只讲BmohBniob对于个人有应用来说再好不过，一个月有20G免费存储空间。Bmob先注册一个好号，然后创建一个应用，最后上传素材。</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://chinawfsl.gitee.io/blog/blog/2019/03/21/美图图集/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="无名小卒">
      <meta itemprop="description" content>
      <meta itemprop="image" content="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1553150146014&di=dc4e5d4bdfbc647f7eca1367401dbc47&imgtype=0&src=http%3A%2F%2Fs9.knowsky.com%2Fbizhi%2Fl%2F20090606%2F200906186%2520%25281%2529.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="无名小卒">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2019/03/21/美图图集/" itemprop="url">美图图集</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-03-21T13:58:55+08:00">
                2019-03-21
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/美图/" itemprop="url" rel="index">
                    <span itemprop="name">美图</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      
        <div class="post-gallery" itemscope itemtype="http://schema.org/ImageGallery">
          
          
            <div class="post-gallery-row">
              <a class="post-gallery-img fancybox" href="http://bruce.u.qiniudn.com/2013/11/27/reading/photos-0.jpg" rel="gallery_cjvhh6ov700067ku4mobalvox" itemscope itemtype="http://schema.org/ImageObject" itemprop="url">
                <img src="http://bruce.u.qiniudn.com/2013/11/27/reading/photos-0.jpg" itemprop="contentUrl">
              </a>
            
          
            
              <a class="post-gallery-img fancybox" href="http://bruce.u.qiniudn.com/2013/11/27/reading/photos-1.jpg" rel="gallery_cjvhh6ov700067ku4mobalvox" itemscope itemtype="http://schema.org/ImageObject" itemprop="url">
                <img src="http://bruce.u.qiniudn.com/2013/11/27/reading/photos-1.jpg" itemprop="contentUrl">
              </a>
            
          
            
              <a class="post-gallery-img fancybox" href="http://pic1.win4000.com/wallpaper/a/58ec73866e1b3.jpg" rel="gallery_cjvhh6ov700067ku4mobalvox" itemscope itemtype="http://schema.org/ImageObject" itemprop="url">
                <img src="http://pic1.win4000.com/wallpaper/a/58ec73866e1b3.jpg" itemprop="contentUrl">
              </a>
            </div>
          
            <div class="post-gallery-row">
              <a class="post-gallery-img fancybox" href="http://img06file.tooopen.com/images/20171228/tooopen_sy_231281461769.jpg" rel="gallery_cjvhh6ov700067ku4mobalvox" itemscope itemtype="http://schema.org/ImageObject" itemprop="url">
                <img src="http://img06file.tooopen.com/images/20171228/tooopen_sy_231281461769.jpg" itemprop="contentUrl">
              </a>
            
          
            
              <a class="post-gallery-img fancybox" href="http://p9.pstatp.com/origin/22cf00053a8a26a2e035.jpg" rel="gallery_cjvhh6ov700067ku4mobalvox" itemscope itemtype="http://schema.org/ImageObject" itemprop="url">
                <img src="http://p9.pstatp.com/origin/22cf00053a8a26a2e035.jpg" itemprop="contentUrl">
              </a>
            
          
            
              <a class="post-gallery-img fancybox" href="http://file01.16sucai.com/d/file/2013/1002/16a0807d2556ee776137f8f809dcadf0.jpg" rel="gallery_cjvhh6ov700067ku4mobalvox" itemscope itemtype="http://schema.org/ImageObject" itemprop="url">
                <img src="http://file01.16sucai.com/d/file/2013/1002/16a0807d2556ee776137f8f809dcadf0.jpg" itemprop="contentUrl">
              </a>
            </div>
          
            <div class="post-gallery-row">
              <a class="post-gallery-img fancybox" href="http://pic.ffpic.com/files/2017/1127/1101gfhfmnazgqbz1.jpg" rel="gallery_cjvhh6ov700067ku4mobalvox" itemscope itemtype="http://schema.org/ImageObject" itemprop="url">
                <img src="http://pic.ffpic.com/files/2017/1127/1101gfhfmnazgqbz1.jpg" itemprop="contentUrl">
              </a>
            
          
            
              <a class="post-gallery-img fancybox" href="http://old.bz55.com/uploads/allimg/151020/140-151020105S0.jpg" rel="gallery_cjvhh6ov700067ku4mobalvox" itemscope itemtype="http://schema.org/ImageObject" itemprop="url">
                <img src="http://old.bz55.com/uploads/allimg/151020/140-151020105S0.jpg" itemprop="contentUrl">
              </a>
            
          
            
              <a class="post-gallery-img fancybox" href="http://himg2.huanqiu.com/attachment2010/2012/1024/20121024083658926.jpg" rel="gallery_cjvhh6ov700067ku4mobalvox" itemscope itemtype="http://schema.org/ImageObject" itemprop="url">
                <img src="http://himg2.huanqiu.com/attachment2010/2012/1024/20121024083658926.jpg" itemprop="contentUrl">
              </a>
            </div>
          
            <div class="post-gallery-row">
              <a class="post-gallery-img fancybox" href="http://www.dmgpark.com/uploadfile/2017/0824/20170824105335713.jpg" rel="gallery_cjvhh6ov700067ku4mobalvox" itemscope itemtype="http://schema.org/ImageObject" itemprop="url">
                <img src="http://www.dmgpark.com/uploadfile/2017/0824/20170824105335713.jpg" itemprop="contentUrl">
              </a>
            
          

          
          </div>
        </div>
      

      
        
          
            <h4 id="本页所有美图来自Google且只做欣赏，不用于任何商业用途，如有侵权，联系删除"><a href="#本页所有美图来自Google且只做欣赏，不用于任何商业用途，如有侵权，联系删除" class="headerlink" title="本页所有美图来自Google且只做欣赏，不用于任何商业用途，如有侵权，联系删除"></a>本页所有美图来自Google且只做欣赏，不用于任何商业用途，如有侵权，联系删除</h4>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://chinawfsl.gitee.io/blog/blog/2019/03/21/hello-world/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="无名小卒">
      <meta itemprop="description" content>
      <meta itemprop="image" content="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1553150146014&di=dc4e5d4bdfbc647f7eca1367401dbc47&imgtype=0&src=http%3A%2F%2Fs9.knowsky.com%2Fbizhi%2Fl%2F20090606%2F200906186%2520%25281%2529.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="无名小卒">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2019/03/21/hello-world/" itemprop="url">Hexo基本命令说明</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-03-21T10:20:58+08:00">
                2019-03-21
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/操作说明/" itemprop="url" rel="index">
                    <span itemprop="name">操作说明</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>欢迎来到<a href="https://hexo.io/" target="_blank" rel="noopener">Hexo</a>! 这是你的第一篇文章. 查看 <a href="https://hexo.io/docs/" target="_blank" rel="noopener">文档</a>以获取更多信息。如果您在使用Hexo时遇到任何问题，可以在<a href="https://hexo.io/docs/troubleshooting.html" target="_blank" rel="noopener">故障排除</a> or 中找到答案，或者您可以在<a href="https://github.com/hexojs/hexo/issues" target="_blank" rel="noopener">GitHub</a>上询问。</p>
<h2 id="快速开始"><a href="#快速开始" class="headerlink" title="快速开始"></a>快速开始</h2><h3 id="创建一个新帖子"><a href="#创建一个新帖子" class="headerlink" title="创建一个新帖子"></a>创建一个新帖子</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo new <span class="string">"老夫的第一篇文章"</span></span><br></pre></td></tr></table></figure>
<p>更多信息: <a href="https://hexo.io/docs/writing.html" target="_blank" rel="noopener">写作</a></p>
<h3 id="运行服务器"><a href="#运行服务器" class="headerlink" title="运行服务器"></a>运行服务器</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo server</span><br></pre></td></tr></table></figure>
<p>更多信息: <a href="https://hexo.io/docs/server.html" target="_blank" rel="noopener">服务器</a></p>
<h3 id="生成静态文件"><a href="#生成静态文件" class="headerlink" title="生成静态文件"></a>生成静态文件</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo generate</span><br></pre></td></tr></table></figure>
<p>更多信息: <a href="https://hexo.io/docs/generating.html" target="_blank" rel="noopener">生成</a></p>
<h3 id="部署到远程站点"><a href="#部署到远程站点" class="headerlink" title="部署到远程站点"></a>部署到远程站点</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo deploy</span><br></pre></td></tr></table></figure>
<p>更多信息: <a href="https://hexo.io/docs/deployment.html" target="_blank" rel="noopener">部署</a></p>
<h3 id="常用指令"><a href="#常用指令" class="headerlink" title="常用指令"></a>常用指令</h3><h4 id="清除缓存文件-db-json-和已生成的静态文件-public"><a href="#清除缓存文件-db-json-和已生成的静态文件-public" class="headerlink" title="清除缓存文件(db.json)和已生成的静态文件(public)"></a>清除缓存文件(db.json)和已生成的静态文件(public)</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo clean</span><br></pre></td></tr></table></figure>
<h4 id="安全模式"><a href="#安全模式" class="headerlink" title="安全模式"></a>安全模式</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo --safe</span><br></pre></td></tr></table></figure>
<h4 id="调试模式"><a href="#调试模式" class="headerlink" title="调试模式"></a>调试模式</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo --debug</span><br></pre></td></tr></table></figure>
<h4 id="简洁模式"><a href="#简洁模式" class="headerlink" title="简洁模式"></a>简洁模式</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo --silent</span><br></pre></td></tr></table></figure>
<h4 id="显示草稿"><a href="#显示草稿" class="headerlink" title="显示草稿"></a>显示草稿</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo --draft</span><br></pre></td></tr></table></figure>
<p>更多信息: <a href="https://hexo.io/zh-cn/docs/commands.html" target="_blank" rel="noopener">指令</a></p>
<h3 id="发布到git上的步骤"><a href="#发布到git上的步骤" class="headerlink" title="发布到git上的步骤"></a>发布到git上的步骤</h3><h4 id="需要修改一下根目录的-config-yml文件，找到URL修改其中的url和root属性"><a href="#需要修改一下根目录的-config-yml文件，找到URL修改其中的url和root属性" class="headerlink" title="需要修改一下根目录的_config.yml文件，找到URL修改其中的url和root属性"></a>需要修改一下根目录的_config.yml文件，找到URL修改其中的url和root属性</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">url: http://chinawfsl.gitee.io/blog/</span><br><span class="line">root: /blog</span><br></pre></td></tr></table></figure>
<p>url 填写你的域名 root 下面应该设置成 /你的项目名 而不是/ 注：如果不改这个在git上启动服务后会导致样式丢失</p>
<h4 id="还是在根目录的-config-yml文件，找到Deployment把它的属性修改为以下内容"><a href="#还是在根目录的-config-yml文件，找到Deployment把它的属性修改为以下内容" class="headerlink" title="还是在根目录的_config.yml文件，找到Deployment把它的属性修改为以下内容"></a>还是在根目录的_config.yml文件，找到Deployment把它的属性修改为以下内容</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">deploy:</span><br><span class="line">  <span class="built_in">type</span>: git</span><br><span class="line">  repo: https://gitee.com/chinawfsl/blog.git</span><br><span class="line">  branch: master</span><br></pre></td></tr></table></figure>
<p>一个正确的部署配置中至少要有 type 参数（也可以多个）<br>repo    库（Repository）地址<br>branch    分支名称。如果您使用的是 GitHub 或 GitCafe 的话，程序会尝试自动检测。<br>message    自定义提交信息 (默认为 Site updated: &#123;&#123; now(‘YYYY-MM-DD HH:mm:ss’) &#125;&#125;)</p>
<h4 id="修改完毕后保存，然后安装hexo-deployer-git-安装命令如下："><a href="#修改完毕后保存，然后安装hexo-deployer-git-安装命令如下：" class="headerlink" title="修改完毕后保存，然后安装hexo-deployer-git,安装命令如下："></a>修改完毕后保存，然后安装<a href="https://github.com/hexojs/hexo-deployer-git" target="_blank" rel="noopener">hexo-deployer-git</a>,安装命令如下：</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ npm install hexo-deployer-git --save</span><br></pre></td></tr></table></figure>
<h4 id="最后就是执行Hexo提供的一键部署功能，让您只需一条命令就能将网站部署到服务器上（如果已近发布过那么要先执行清除缓存命令，该命令上面有写）"><a href="#最后就是执行Hexo提供的一键部署功能，让您只需一条命令就能将网站部署到服务器上（如果已近发布过那么要先执行清除缓存命令，该命令上面有写）" class="headerlink" title="最后就是执行Hexo提供的一键部署功能，让您只需一条命令就能将网站部署到服务器上（如果已近发布过那么要先执行清除缓存命令，该命令上面有写）"></a>最后就是执行Hexo提供的一键部署功能，让您只需一条命令就能将网站部署到服务器上（如果已近发布过那么要先执行清除缓存命令，该命令上面有写）</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo deploy</span><br></pre></td></tr></table></figure>
<h4 id="原理：当初次新建一个库的时候，库将自动包含一个master分支。请在这个分支下进行写作和各种配置来完善您的网页。当执行hexo-deploy时，Hexo会创建或更新另外一个用于部署的分支，这个分支就是-config-yml配置文件中指定的分支。Hexo会将生成的站点文件推送至该分支下，并且完全覆盖该分支下的已有内容。因此，部署分支应当不同于写作分支。（一个推荐的方式是把master作为写作分支，另外使用public分支作为部署分支。）值得注意的是，hexo-deploy并不会对本地或远程的写作分支进行任何操作，因此依旧需要手动推送写作分支的所有改动以实现版本控制。此外，如果您的Github-Pages需要使用CNAME文件自定义域名，请将CNAME文件置于写作分支的source-dir目录下，只有这样hexo-deploy才能将CNAME文件一并推送至部署分支。"><a href="#原理：当初次新建一个库的时候，库将自动包含一个master分支。请在这个分支下进行写作和各种配置来完善您的网页。当执行hexo-deploy时，Hexo会创建或更新另外一个用于部署的分支，这个分支就是-config-yml配置文件中指定的分支。Hexo会将生成的站点文件推送至该分支下，并且完全覆盖该分支下的已有内容。因此，部署分支应当不同于写作分支。（一个推荐的方式是把master作为写作分支，另外使用public分支作为部署分支。）值得注意的是，hexo-deploy并不会对本地或远程的写作分支进行任何操作，因此依旧需要手动推送写作分支的所有改动以实现版本控制。此外，如果您的Github-Pages需要使用CNAME文件自定义域名，请将CNAME文件置于写作分支的source-dir目录下，只有这样hexo-deploy才能将CNAME文件一并推送至部署分支。" class="headerlink" title="原理：当初次新建一个库的时候，库将自动包含一个master分支。请在这个分支下进行写作和各种配置来完善您的网页。当执行hexo deploy时，Hexo会创建或更新另外一个用于部署的分支，这个分支就是_config.yml配置文件中指定的分支。Hexo会将生成的站点文件推送至该分支下，并且完全覆盖该分支下的已有内容。因此，部署分支应当不同于写作分支。（一个推荐的方式是把master作为写作分支，另外使用public分支作为部署分支。）值得注意的是，hexo deploy并不会对本地或远程的写作分支进行任何操作，因此依旧需要手动推送写作分支的所有改动以实现版本控制。此外，如果您的Github Pages需要使用CNAME文件自定义域名，请将CNAME文件置于写作分支的source_dir目录下，只有这样hexo deploy才能将CNAME文件一并推送至部署分支。"></a>原理：当初次新建一个库的时候，库将自动包含一个master分支。请在这个分支下进行写作和各种配置来完善您的网页。当执行hexo deploy时，Hexo会创建或更新另外一个用于部署的分支，这个分支就是_config.yml配置文件中指定的分支。Hexo会将生成的站点文件推送至该分支下，并且完全覆盖该分支下的已有内容。因此，部署分支应当不同于写作分支。（一个推荐的方式是把master作为写作分支，另外使用public分支作为部署分支。）值得注意的是，hexo deploy并不会对本地或远程的写作分支进行任何操作，因此依旧需要手动推送写作分支的所有改动以实现版本控制。此外，如果您的Github Pages需要使用CNAME文件自定义域名，请将CNAME文件置于写作分支的source_dir目录下，只有这样hexo deploy才能将CNAME文件一并推送至部署分支。</h4><p>更多信息: <a href="https://hexo.io/zh-cn/docs/deployment" target="_blank" rel="noopener">指令</a></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
  </section>

  


          </div>
          


          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1553150146014&di=dc4e5d4bdfbc647f7eca1367401dbc47&imgtype=0&src=http%3A%2F%2Fs9.knowsky.com%2Fbizhi%2Fl%2F20090606%2F200906186%2520%25281%2529.jpg" alt="无名小卒">
            
              <p class="site-author-name" itemprop="name">无名小卒</p>
              <p class="site-description motion-element" itemprop="description">如果有天我们湮没在人潮中,庸碌一生,那是因为我们没有努力要活的丰盛</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blog/archives/">
              
                  <span class="site-state-item-count">4</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/blog/categories/index.html">
                  <span class="site-state-item-count">3</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/blog/tags/index.html">
                  <span class="site-state-item-count">3</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-inline">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-globe"></i>
                友情链接
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="http://cyc2018.gitee.io/cs-notes/#/README" title="Java知识库" target="_blank">Java知识库</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://theme-next.iissnan.com/" title="NexT官方文档" target="_blank">NexT官方文档</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">无名小卒</span>

  
</div>


<div class="powered-by">
<i class="fa fa-user-md"></i><span id="busuanzi_container_site_uv">
  本站总访问量<span id="busuanzi_value_site_uv"></span>次
</span>
</div>
 <!-- <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>-->




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/blog/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/schemes/pisces.js?v=5.1.4"></script>



  

  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
